package demo2;

public class Student implements Comparable<Student>{
    String name;
    int age;


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        if(this.age-o.age>0){
            return 1;
        }
        if(this.age-o.age==0){
            return this.name.compareTo(o.name);
        }
        return -1;
    }
}
